package com.dddframework.core.contract;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * 分页数据对象
 *
 * @param <T>
 */
@Data
@AllArgsConstructor
public class Page<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    // 列表数据
    private List<T> records;
    // 总记录数
    private Long total;
    // 回写当前页
    private Long current;
    // 回写每页大小
    private Long size;

    public static <T> Page<T> succeed(List<T> records, long total, long current, long size) {
        return new Page<>(records, total, current, size);
    }

    public static <T> Page<T> empty() {
        return new Page<>(Collections.emptyList(), 0L, 0L, 0L);
    }

}